//
//  TravelNotesTableViewCell.m
//  旅游咨询
//
//  Created by 徐斌 on 15/4/13.
//  Copyright (c) 2015年 xubin. All rights reserved.
//
#import "TravelNotesTableViewCell.h"


@implementation TravelNotesTableViewCell

- (void)dealloc
{
    [_myImageView release];
    [_nameLabel release];
    [_placeLabel release];
    [_userImage release];
    [_userlabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatSubViews];
    }
    return self;
    
}

- (void)creatSubViews
{
    self.myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 5, WidthZ - 20, (WidthZ - 20) * 0.75)];
//    NSLog(@"with %f", self.contentView.frame.size.width);
//    NSLog(@"heigh %f", self.contentView.frame.size.height);
    
    // 把imageview变成圆角
    self.myImageView.layer.cornerRadius = 5;
    self.myImageView.layer.masksToBounds = YES;
    self.myImageView.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.myImageView];
   
    
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 8, self.contentView.frame.size.width, self.myImageView.frame.size.height / 10)];
    [self.myImageView addSubview:self.nameLabel];
    
    
    self.placeLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, (self.myImageView.frame.size.height / 10) + 15, self.contentView.frame.size.width, 12)];
    self.placeLabel.font = [UIFont systemFontOfSize:12];
    [self.myImageView addSubview:self.placeLabel];
    
    self.userImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, self.myImageView.frame.size.height - 40, 30, 30)];
    self.userImage.layer.cornerRadius = 15;
    self.userImage.layer.masksToBounds = YES;
    [self.myImageView addSubview:self.userImage];
    
    self.userlabel = [[UILabel alloc]initWithFrame:CGRectMake(12 + self.userImage.frame.size.width, self.myImageView.frame.size.height - 30, 150, 10)];
    self.userlabel.font = [UIFont systemFontOfSize:10];
    [self.myImageView addSubview:self.userlabel];
    
    [_myImageView release];
    [_nameLabel release];
    [_userlabel release];
    [_userImage release];
    [_placeLabel release];
    
    
}

- (void)setModel:(TravelNotesModel *)model
{
    
// 重写set方法(赋值)
    NSURL *url = [NSURL URLWithString:model.cover_image_default];
    [self.myImageView sd_setImageWithURL:url];
    self.nameLabel.text = model.name;
    self.placeLabel.text = model.popular_place_str;
    self.userlabel.text = [model.user objectForKey:@"name"];
    NSURL *userUrl = [NSURL URLWithString:[model.user objectForKey:@"avatar_m"]];
    [self.userImage sd_setImageWithURL:userUrl];
   
    
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
